home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.3d26 source / tn3270 / util.c < prev    next >
Text File  |  1991-01-21  |  6KB  |  267 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.3d21, January 17, 1991
  5.  *  Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistant Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #define __SEG__ 3270seg2
  34. #include "maclib.h"
  35. #include "termdef.h"
  36. #include "globals.h"
  37.  
  38. extern char smallscreen;        /* complete 24 x 80 window doesn't fit */
  39.  
  40. #define    IAC    255        /* Telnet protocol interpret as command: */
  41.  
  42. movmem(src, dest, len)
  43. char *src, *dest;
  44. short len;
  45. {
  46. memcpy(dest, src, len);
  47. }
  48.  
  49. tcpmovmem(src, dest, len)
  50. unsigned char *src, *dest;
  51. short *len;
  52. {
  53. register short i, copylen;
  54.  
  55. if (tcpflg) {
  56.     if ((*len) == 0) return;
  57.     copylen = 0;
  58.     for (i=0; i < (*len); i++) {
  59.         if (src[i] == IAC) {
  60.             dest[copylen++] = IAC;
  61.             dest[copylen++] = IAC;
  62.             }
  63.         else {
  64.             dest[copylen++] = src[i];
  65.             }
  66.         }
  67.     (*len) = copylen;
  68.     }
  69. else {
  70.     memcpy(dest, src, *len);
  71.     }
  72. }
  73.  
  74. setmem(area, len, value)
  75. char * area;
  76. short len;
  77. char value;
  78. {
  79. memset(area, value, len);
  80. }
  81.  
  82. char * ctop(s)
  83. char *s;
  84. {
  85. return(c2pstr(s));
  86. }
  87.  
  88. char * ptoc(s)
  89. char *s;
  90. {
  91. return(p2cstr(s));
  92. }
  93.  
  94. GetGlobalRect(window, globalRect)
  95. WindowPtr window;
  96. Rect * globalRect;
  97. {
  98. GrafPtr gp;
  99.  
  100. GetPort(&gp);
  101. SetPort(window);
  102. (*globalRect) = window->portRect;
  103. LocalToGlobal(&(globalRect->top));
  104. LocalToGlobal(&(globalRect->bottom));
  105. SetPort(gp);
  106. }
  107.  
  108. defxtab(xtabinfo, xtab)
  109. unsigned char **xtabinfo;
  110. unsigned char *xtab;
  111. {
  112. Size infosize;
  113. register short i;
  114.  
  115. /* generate default table */
  116. for (i=0; i < 256; i++) {
  117.     xtab[i] = i;
  118.     }
  119.  
  120. /* modify specified values */
  121. infosize = GetHandleSize((Handle)xtabinfo); 
  122. /* ensure length is a multiple of two (as it should be) */
  123. infosize >>= 1;
  124. infosize <<= 1;
  125. if (infosize < 2) return;
  126. for (i=0; i < infosize; i += 2) {
  127.     xtab[(*xtabinfo)[i]] = (*xtabinfo)[i+1];
  128.     }
  129. }
  130.  
  131. getdeskrect(r)
  132. Rect *r;
  133. {
  134. static RgnHandle *GrayRgn = (RgnHandle *)0x9ee;
  135.  
  136. (*r) = (**GrayRgn)->rgnBBox;
  137. }
  138.  
  139. unsigned char getmodel(rows, cols)
  140. short rows, cols;
  141. {
  142.                     /* note: for models 4 and 5, only 3278 is used, since
  143.                               there are no real 3279-4 or -5 terminals    */
  144. if (colormac) {
  145.     if ((rows == 32) && (cols == 80)) return(MDL32793);
  146.     else if ((rows == 43) && (cols == 80)) return(MDL32784);
  147.     else if ((rows == 27) && (cols == 132)) return(MDL32785);
  148.     else return(MDL32792);
  149.     }
  150. else {
  151.     if ((rows == 32) && (cols == 80)) return(MDL32783);
  152.     else if ((rows == 43) && (cols == 80)) return(MDL32784);
  153.     else if ((rows == 27) && (cols == 132)) return(MDL32785);
  154.     else return(MDL32782);
  155.     }
  156. }
  157.  
  158. adjmove(wr)            /* wr is the rectangle for a window in global coordinates */
  159. Rect *wr;            /* the position of the rectangle is adjusted to fit on 
  160.                        on the screen as well as possible */
  161. {
  162. Rect r, devrect;
  163. Point ctr;
  164. GDHandle devgdev;
  165. char found;
  166. char devok;
  167. short adj;
  168.  
  169.  
  170. r = *wr;            /* local copy of window rectange */
  171.                     /* get center point and corresponding device rectange */
  172. ctr.h = (r.left + r.right)/2;
  173. ctr.v = (r.top + r.bottom)/2;
  174. if (colormac) {
  175.     found = 0;
  176.     devgdev = GetDeviceList();
  177.     while (devgdev != 0) {
  178.         devrect = (*devgdev)->gdRect;
  179.         if (PtInRect(&ctr, &devrect)) {
  180.             found = 1;
  181.             break;
  182.             }
  183.         else {
  184.             devgdev = GetNextDevice(devgdev);
  185.             }
  186.         }
  187.     if (!found) {
  188.         devgdev = GetMainDevice();
  189.         if (devgdev == 0) {
  190.             return;    /* shouldn't happen */
  191.             }
  192.         else {
  193.             devrect = (*devgdev)->gdRect;
  194.             }
  195.         }
  196.     }
  197. else {
  198.     devrect = qd.screenBits.bounds;
  199.     }
  200. /* adjust for menu bar */
  201. if ((devrect.top == 0) && (devrect.left == 0)) {
  202.     if (smallscreen) {
  203.         devrect.top = 4;
  204.         }
  205.     else {
  206.         devrect.top = 20;
  207.         }
  208.     }
  209.  
  210. /* return if window is entirely in device rectangle */
  211. if ((devrect.top <= r.top) && (devrect.bottom >= r.bottom) &&
  212.     (devrect.left <= r.left) && (devrect.right >= r.right)) {
  213.     return;
  214.     }
  215. if (colormac) {
  216.     /* check window will fit on device */
  217.     devok = ((devrect.bottom - devrect.top) >= (r.bottom - r.top)) &&
  218.              ((devrect.right - devrect.left) >= (r.right - r.left));
  219.     /* if not, use entire desktop */
  220.     if (!devok) {
  221.         getdeskrect(&devrect);
  222.         if (devrect.top == 0) {
  223.             if (smallscreen) {
  224.                 devrect.top = 4;
  225.                 }
  226.             else {
  227.                 devrect.top = 20;
  228.                 }
  229.             }
  230.         if ((devrect.top <= r.top) && (devrect.bottom >= r.bottom) &&
  231.             (devrect.left <= r.left) && (devrect.right >= r.right)) {
  232.             return;
  233.             }
  234.         }
  235.     }
  236.             /* following order ensures that top left corner is in window */
  237. /* make right edge fit */
  238. adj = r.right - devrect.right;
  239. if (adj > 0) {
  240.     r.right -= adj;
  241.     r.left -= adj;
  242.     }
  243.     
  244. /* make bottom edge fit */
  245. adj = r.bottom - devrect.bottom;
  246. if (adj > 0) {
  247.     r.bottom -= adj;
  248.     r.top -= adj;
  249.     }
  250.     
  251. /* make left edge fit */
  252. adj = devrect.left - r.left;
  253. if (adj > 0) {
  254.     r.left += adj;
  255.     r.right += adj;
  256.     }
  257.     
  258. /* make top edge fit */
  259. adj = devrect.top - r.top;
  260. if (adj > 0) {
  261.     r.top += adj;
  262.     r.bottom += adj;
  263.     }
  264.     
  265. (*wr) = r;
  266. }
  267.